﻿<%
Class sangong_class
    Public Function online()
        dim rs,sql,str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select count(*) as nid FROM qingtian_reton"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
		str=rs("nid")
	else
		str=0
	end if
	Rs.close
	set rs=nothing
	online=str
     End Function
    Public Function tj()
        dim rs,sql,i
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where nid="&qingtian.nid
	Rs.Open Sql,cn,1,3
	if not (rs.bof and rs.eof) then
        rs("time")=now
	else
	rs.addnew
        rs("time")=now
	rs("nid")=qingtian.nid
        rs("donging")="进入热血梭哈游戏大厅"
        rs("dotime")=now
	end if
	rs.update
	Rs.close
	Sql = "select * FROM qingtian_reton where DATEDIFF('h', [time], now()) > 24 order by time asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
		For i=1 to rs.RecordCount
		rs.delete
		Rs.MoveNext
		next
		end if
		Rs.close
	set rs=nothing
     End Function
    Public Function pd(str)
        dim rs,sql,strr
        strr=str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select money FROM qingtian_fangjian where id="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
           if conn.execute("select money from [qingtian_user] where sid='"&qingtian.Formatsid(sid)&"'")("money")<rs("money")*5 then
           qingtian.err("你的"&qingtian.bi&"不足,进入该房间最小需要"&rs("money")*5&""&qingtian.bi&".<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
           end if
        else
           qingtian.err("没有该房间,<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function moname(str)
        dim rs,sql,i,strr,moname1
        strr=str
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
	For i=1 to rs.RecordCount
        if i=1 then
        moname1="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>"
        else
        moname1="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>" & "," & moname1
        end if
	Rs.MoveNext
	next
        else
        moname1="暂无玩家"        
	end if
	Rs.close
	set rs=nothing
        moname=moname1
     End Function
    Public Function moname3(str,str2)
        dim rs,sql,i,strr,strr2
        strr=str
        strr2=str2
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select top 1 nid FROM qingtian_reton where aid="&strr&" and ton=2"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname3="(<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>)"
        else
        moname3="(空)[<a href='gamed.asp?act=1&amp;pid="&strr2&"&amp;id="&strr&"&amp;sid="&sidd&"'>坐庄</a>]"     
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function moname2(str,str2)
        dim rs,sql,i,strr,strr2
        strr=str
        strr2=str2
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr&" and ton<>2"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
	For i=1 to rs.RecordCount
        if i=1 then
        moname2="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>"
        else
        moname2="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>" & "," & moname1
        end if
	Rs.MoveNext
	next
        else
        moname2="空"     
	end if
	Rs.close
	set rs=nothing
        moname2="("&moname2&")[<a href='gamed.asp?act=2&amp;pid="&strr2&"&amp;id="&strr&"&amp;sid="&sidd&"'>坐闲</a>]"
     End Function
    Public Function tonn()
        dim rs,sql
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select ton,aid,bid FROM qingtian_reton where nid="&qingtian.nid
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        if rs("ton")<>0 then
        if rs("bid")>4 then
        tonn="状态:游戏中<a href='gamedd.asp?action=login&amp;pid="&rs("bid")&"&amp;id="&rs("aid")&"&amp;sid=" & sidd & "'>返回</a>"
        else        
        tonn="状态:游戏中<a href='gamed.asp?action=login&amp;pid="&rs("bid")&"&amp;id="&rs("aid")&"&amp;sid=" & sidd & "'>返回</a>"
        end if
        else
        tonn="状态:等待游戏"
	end if
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function mobe(str)
        dim rs,sql,i,strr,moname1
        strr=str
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs.RecordCount
        else
        moname1=0
	end if
	Rs.close
	set rs=nothing
        mobe=moname1
     End Function
    Public Function moton(str,str1,str2)
        dim rs,sql,i,strr,strr1,strr2
        strr=str
        strr1=str1
        strr2=str2
        if strr=0 then
        moton="等待玩家<a href='gamed.asp?pid="&strr2&"&amp;id="&strr1&"&amp;sid=" & sidd & "'>加入</a>"
        else
        moton="游戏正在进行中"
        end if
        if mobe(strr1)=6 then moton="游戏正在进行中"
     End Function
    Public Function motonton(str,str1,str2)
        dim rs,sql,i,strr,strr1,strr2
        strr=str
        strr1=str1
        strr2=str2
        if strr=0 and mobe(strr1)=1 then
        motonton="等待玩家<a href='gamedd.asp?action=login&amp;pid="&strr2&"&amp;id="&strr1&"&amp;sid=" & sidd & "'>挑战</a>"
        elseif strr=0 and mobe(strr1)=0 then
        motonton="等待玩家<a href='gamedd.asp?pid="&strr2&"&amp;id="&strr1&"&amp;sid=" & sidd & "'>坐庄</a>"
        else
        motonton="游戏正在进行中"
        end if
        if mobe(strr1)=2 then motonton="游戏正在进行中"
     End Function
    Public Function suiji(str)
        dim monber,j,i,strr,temp,a1,a2,t,a
        strr=str
        monber="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52"
        monber=split(monber,",")
        Randomize()
        a=int(rnd*12+1)
        for i=1 to 100
            a1=int(rnd*51+1)
            a2=int(rnd*51+1)
        temp=monber(a1)
        monber(a1)=monber(a2)
        monber(a2)=temp
        next
        for j=a to strr
        if j=a then
        suiji=monber(a)
        else
        suiji=suiji&","&monber(j)
        end if
        next
        for t=0 to a-1
        suiji=suiji&","&monber(t)
        next       
     End Function
    Public Function namefa(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_fangd where id="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
        else
        qingtian.err("没有该房间,<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
	end if
	Rs.close
	set rs=nothing
        namefa=moname1
     End Function
    Public Function namere(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_reton where nid="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
	end if
	Rs.close
	set rs=nothing
        namere=moname1
     End Function
    Public Function namejian(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_fangjian where id="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
	end if
	Rs.close
	set rs=nothing
        namejian=moname1
     End Function
    Public Function suoa(str,str1)
        dim strr,strr1,rs,sql,a,suoaa,i,c,b,d
        strr=str
        strr1=clng(str1)-1
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where aid="&strr&" order by id asc"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof)  then
        d=0
	For i=1 to rs.RecordCount
        b=d
        c=split(rs("c"),",")
        d=c(strr1)
        if daxiao(d)>daxiao(b) then
        suoaa=rs("nid")
        elseif daxiao(d)=daxiao(b) then
          if huase(d)>huase(b) then
                suoaa=rs("nid")
          end if 
        end if               
	Rs.MoveNext
	next           
	end if
	Rs.close
	set rs=nothing
        suoa=suoaa
     End Function
    Public Function time1(str)
        dim rs,sql,i
   	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select time FROM qingtian_reton where aid="&str&" and ku=1 order by id asc"
	Rs.Open Sql,cn,1,3
		if not(rs.bof and rs.eof)  then 
 		For i=1 to rs.RecordCount
                rs("time")=now
	        rs.update
		Rs.MoveNext
		next
        end if
	Rs.close
        set rs=nothing
     End Function
    Public Function game1(str)
        dim strr,rs,sql,c,a,i,h,mon,pid
	pid=Request.QueryString("pid")
	if pid="" then pid=1
	if not isnumeric(pid) then pid=1
	pid=clng(pid)
        strr=str
        mon=sangong.namejian("money",pid)
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where aid="&strr&" order by id asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
                b=rs.RecordCount*mon*0.1
                h=suiji("51")
                c=split(h,",")
		For i=1 to rs.RecordCount
                rs("c")=c((i-1)*5)&","&c((i-1)*5+1)&","&c((i-1)*5+2)&","&c((i-1)*5+3)&","&c((i-1)*5+4)
                rs("b")=int(mon*0.1)
                rs("time")=now()
                qingtian.pay -int(mon*0.1),rs("nid")                
                if rs("ton")=2 then
                rs("a")=1
                end if
	        rs.update                
		Rs.MoveNext
		next           
		end if
		Rs.close
	Sql = "select * FROM qingtian_reton where aid="&strr&" and ton<>2 order by id asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
		For i=1 to rs.RecordCount
                rs("a")=i+1
	        rs.update                
		Rs.MoveNext
		next           
		end if
		Rs.close
	set rs=nothing
                cn.Execute("update qingtian_fangd set h="&b&",b="&int(mon*0.1)&",u=1 where id="&strr)
     End Function

    Public Function pai(str,str1)
        dim strr,i,paii,a1
        strr=str
        strr1=clng(str1)-1
        if strr1>5 then strr1=5
        strr=split(strr,",")
        for i=0 to strr1
        a1=paizi(strr(i))
        if tu="&amp;aitd=1'>图片显示</a>" then
        paii=paii&"."&a1
        else
        paii="<img src='/game/sangon/img/"&strr(i)&".png' alt='"&a1&"' noselect = 'true' />" & paii
        end if
        next
        pai=paii
     End Function
    Public Function aapai(str,str1)
        dim strr,i,paii,a1,strr1
        strr=str
        strr1=clng(str1)-1
        if strr1>5 then strr1=5
        strr=split(strr,",")
        for i=0 to strr1
        a1=paizi(strr(i))
        if tu="&amp;aitd=1'>图片显示</a>" then
        if i=0 then
        paii="空"
        else
        paii=paii&"."&a1
        end if
        else
        if i=0 then
        paii="<img src='/game/sangon/img/0.png' alt='空' noselect = 'true' />"
        else
        paii="<img src='/game/sangon/img/"&strr(i)&".png' alt='"&a1&"' noselect = 'true' />" & paii
        end if
        end if
        next
        aapai=paii
     End Function
    Public Function paizi(str)
        dim strr,a1,a2,paizi1
        strr=str
                a2=strr mod 4
                if a2<>0 then
                a1=int(strr/4)+1
                else 
                a1=int(strr/4)  
                end if
                select case a2
                case "0"
                paizi1="黑桃"
                case "1"
                paizi1="方块"
                case "2"
                paizi1="梅花"
                case "3"
                paizi1="红桃"
                End Select
                select case a1
                case "1"
                a1="A"
                case "11"
                a1="J"
                case "12"
                a1="Q"
                case "13"
                a1="K"
                End Select
                paizi=paizi1&a1
     End Function
    Public Function tu()
        dim rs,sql,str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select top 1 tu FROM qingtian_reton where nid="&qingtian.nid&""
	Rs.Open Sql,cn,1,3
        if Request.QueryString("aitd")="1" then rs("tu")=0
        if Request.QueryString("aitd")="0" then rs("tu")=1
	rs.update
        if rs("tu") then
        str="&amp;aitd=1'>图片显示</a>"
        else 
        str="&amp;aitd=0'>文字显示</a>"
        end if
	Rs.close
	set rs=nothing
	tu=str
     End Function
    Public Function gamejie(str1,str2)

        dim rs,sql,strs,i,pp,tt,aa,a,nid,d,id,pid,bodyy
        id=str1
        pid=str2 
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where aid="&id&" and ku=1 order by a desc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
                if rs.RecordCount=1 then 
                tkkk=true
                else
                tkkk=false
                end if
 		For i=1 to rs.RecordCount
                if i=1 then 
                c=rs("c")
                nd=rs("nid")
                end if 
                c=c&"|"&rs("c")
                nd=nd&"|"&rs("nid")
		Rs.MoveNext
		next
                c=split(c,"|")
                nd=split(nd,"|")
                end if
       Rs.close
       set rs=nothing
       ttcc1=UBound(c)
       ttcc=ttcc1-1
       For i=0 To ttcc
       cc1=split(c(i),",")
       cc2=split(c(i+1),",")
       cc3=sangong.ret(cc1,cc2)
       if cc3=1 then
       nd(i+1)=nd(i)       
       c(i+1)=c(i)
       end if       
       next
       nid=nd(ttcc1)
       cn.Execute("update qingtian_fangd set nid="&nid&" where id="&id)  
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where nid="&qingtian.nid
	Rs.Open Sql,cn,1,3
	if not (rs.bof and rs.eof) then
        rs("donging")="在游戏中赢得"&namefa("h",id)-rs("b")&""&qingtian.bi
        rs("dotime")=now
        rs("shen")=rs("shen")+1
        rs("m")=rs("m")+namefa("h",id)-rs("b")
	end if
	rs.update
	Rs.close
       set rs=nothing
        qingtian.pay namefa("h",id),nid             
          if clng(nid)=clng(qingtian.nid) then
          bodyy="恭喜,你赢了本局游戏系统为你增加"&zi&""&namefa("h",id)&""&qingtian.bi&""&zi0&"!<br/>"
          qingtian.addong("在游戏[url=/game/suoha/index.asp?sid=[sid]]热血梭哈[/url]中赢得了"&qingtian.bi&"")         
          else
          bodyy="恭喜,"&qingtian.name(nid)&"赢了本局游戏系统为Ta增加"&zi&""&namefa("h",id)&""&qingtian.bi&""&zi0&"!<br/>"
          qingtian.addong("在游戏[url=/game/suoha/index.asp?sid=[sid]]热血梭哈[/url]中输掉了"&qingtian.bi&"") 
          end if
          if tkkk=true then bodyy="本局游戏玩家弃权,"&qingtian.name(nid)&"赢了本局,系统为Ta增加"&zi&""&namefa("h",id)&""&qingtian.bi&""&zi0&"!<br/>"
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where aid="&id&" order by id asc"
	Rs.Open Sql,cn,1,1
		if not (rs.bof and rs.eof)  then            
 		For i=1 to rs.RecordCount
                if rs("nid")=qingtian.nid then
                tt="你的"
                else
                tt=qingtian.name(rs("nid"))
                end if
                ccccc=split(rs("c"),",")
                aa=zajinn(ccccc)
                if rs("ton")=2 then 
                pp=""&zi&"(庄)"&zi0&""
                else
                pp=""
                end if
                bodyy=bodyy&tt&"的牌"&pp&":"&zi&""&aa&""&zi0&"<br/>"&pai(rs("c"),5)&"<br/>"                          
		Rs.MoveNext
		next
                end if
       Rs.close
       set rs=nothing 
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select top 1 * FROM qingtian_fangd where id="&id&" order by id asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then 
                rs("ton")=2
                rs("time")=now()
	rs.update 
        end if
	Rs.close
       set rs=nothing
          if pid<5 then
          bodyy=bodyy&"请等待10秒[<a href='gamed.asp?Action=login&amp;id="&id&"&amp;pid="&pid&"&amp;sid="&sidd&"'>刷新</a>]<br/>"
          else
          bodyy=bodyy&"游戏即将结束请[<a href='gamedd.asp?Action=login&amp;id="&id&"&amp;pid="&pid&"&amp;sid="&sidd&"'>刷新</a>]<br/>"
          end if
         gamejie=bodyy
     End Function
    Public Function MaxPoint(ary)
		MaxPoint=ary(1)
		If ary(2)>MaxPoint Then MaxPoint=ary(2)
		If ary(3)>MaxPoint Then MaxPoint=ary(3)
		If ary(4)>MaxPoint Then MaxPoint=ary(4)
		If ary(5)>MaxPoint Then MaxPoint=ary(5)
	End Function	
    Public Function Resort(ary)'//由大到小排序//
		Dim tmp
		Dim tmp2
		tmp=0

		For i=1 To UBound(ary)
			tmp=i

			For k=i+1 To UBound(ary)
				If ary(k)>ary(tmp) Then tmp=k
			Next 
	
			If tmp<>i Then 
				tmp2=ary(tmp)
				ary(tmp)=ary(i)
				ary(i)=tmp2
			End If
		Next 
	End Function
   Public Function Ret(str1,str2)
	Dim T_Pt(5)
	Dim T_Cr(5)
	Dim T_Lvl
	Dim T_MaxPt
	Dim T_Pair
	Dim Pt(5)
	Dim Cr(5)
	Dim Lvl
	Dim MaxPt
	Dim Pair
        For i=0 To UBound(str1)
		T_Pt(i+1)=daxiao(str1(i))
		T_Cr(i+1)=huase(str1(i))
        Next
        For i=0 To UBound(str2)
		Pt(i+1)=daxiao(str2(i))
		Cr(i+1)=huase(str2(i))
        Next
                Resort T_Pt
                Resort Pt

		'//计算擂主牌型//
		If (T_Pt(1)=T_Pt(2) AND T_Pt(1)=T_Pt(3) AND T_Pt(1)=T_Pt(4)) OR (T_Pt(5)=T_Pt(2) AND T_Pt(5)=T_Pt(3) AND T_Pt(5)=T_Pt(4)) Then 
			T_Lvl=8'//铁支//
		ElseIf  (T_Pt(1)-T_Pt(2)=1 AND T_Pt(2)-T_Pt(3)=1 AND T_Pt(3)-T_Pt(4)=1 AND T_Pt(4)-T_Pt(5)=1) Then
			If T_Cr(1)=T_Cr(2) AND T_Cr(1)=T_Cr(3) AND T_Cr(1)=T_Cr(4) AND T_Cr(1)=T_Cr(5) Then
				T_Lvl=9'//同花顺//
			Else
				T_Lvl=5'//顺子//
			End If
		ElseIf T_Cr(1)=T_Cr(2) AND T_Cr(1)=T_Cr(3) AND T_Cr(1)=T_Cr(4) AND T_Cr(1)=T_Cr(5) Then
			T_Lvl=6'//同花//
		ElseIf (T_Pt(1)=T_Pt(3) AND T_Pt(2)=T_Pt(3) ) OR (T_Pt(4)=T_Pt(3) AND T_Pt(5)=T_Pt(3)) OR (T_Pt(4)=T_Pt(3) AND T_Pt(2)=T_Pt(3)) Then
                        If (T_Pt(1)=T_Pt(2) AND T_Pt(4)=T_Pt(3) AND T_Pt(5)=T_Pt(3)) OR (T_Pt(4)=T_Pt(5) AND T_Pt(1)=T_Pt(3) AND T_Pt(2)=T_Pt(3)) then 
			T_Lvl=7'//葫芦//
                        else
			T_Lvl=4'//三条//
                        end if
		ElseIf T_Pt(1)=T_Pt(2) OR T_Pt(3)=T_Pt(4) OR T_Pt(2)=T_Pt(3) OR T_Pt(4)=T_Pt(5) Then 
                        if (T_Pt(1)=T_Pt(2) AND T_Pt(3)=T_Pt(4)) OR (T_Pt(1)=T_Pt(2) AND T_Pt(4)=T_Pt(5)) OR (T_Pt(2)=T_Pt(3) AND T_Pt(4)=T_Pt(5)) then
			T_Lvl=3'//二对//
                        if T_Pt(2)=T_Pt(3) AND T_Pt(4)=T_Pt(5) then
                        T_MaxPt=T_Pt(2)
                        T_Pair=T_Cr(2)
                        else
                        T_MaxPt=T_Pt(1)
                        T_Pair=T_Cr(1)
                        end if
                        else
			T_Lvl=2'//对子//
                        if T_Pt(1)=T_Pt(2) then
                        T_MaxPt=T_Pt(1)
                        T_Pair=T_Cr(1)
                        elseif T_Pt(2)=T_Pt(3) then 
                        T_MaxPt=T_Pt(2)
                        T_Pair=T_Cr(2)
                        elseif T_Pt(3)=T_Pt(4) then 
                        T_MaxPt=T_Pt(3)
                        T_Pair=T_Cr(3)
                        elseif T_Pt(4)=T_Pt(5) then 
                        T_MaxPt=T_Pt(4)
                        T_Pair=T_Cr(4)
                        end if
                        end if
		Else
			T_Lvl=1'//散牌一堆//
		End If 

		'//计算擂主牌型//
		If (Pt(1)=Pt(2) AND Pt(1)=Pt(3) AND Pt(1)=Pt(4)) OR (Pt(5)=Pt(2) AND Pt(5)=Pt(3) AND Pt(5)=Pt(4)) Then 
			Lvl=8'//铁支//
		ElseIf  (Pt(1)-Pt(2)=1 AND Pt(2)-Pt(3)=1 AND Pt(3)-Pt(4)=1 AND Pt(4)-Pt(5)=1) Then
			If Cr(1)=Cr(2) AND Cr(1)=Cr(3) AND Cr(1)=Cr(4) AND Cr(1)=Cr(5) Then
				Lvl=9'//同花顺//
			Else
				Lvl=5'//顺子//
			End If
		ElseIf Cr(1)=Cr(2) AND Cr(1)=Cr(3) AND Cr(1)=Cr(4) AND Cr(1)=Cr(5) Then
			Lvl=6'//同花//
		ElseIf (Pt(1)=Pt(3) AND Pt(2)=Pt(3) ) OR (Pt(4)=Pt(3) AND Pt(5)=Pt(3)) OR (Pt(2)=Pt(3) AND Pt(4)=Pt(3)) Then
                        If (Pt(1)=Pt(2) AND Pt(4)=Pt(3) AND Pt(5)=Pt(3)) OR (Pt(4)=Pt(5) AND Pt(1)=Pt(3) AND Pt(2)=Pt(3)) then 
			Lvl=7'//葫芦//
                        else
			Lvl=4'//三条//
                        end if
		ElseIf Pt(1)=Pt(2) OR Pt(3)=Pt(4) OR Pt(2)=Pt(3) OR Pt(4)=Pt(5) Then 
                        if (Pt(1)=Pt(2) AND Pt(3)=Pt(4)) OR (Pt(1)=Pt(2) AND Pt(4)=Pt(5)) OR (Pt(2)=Pt(3) AND Pt(4)=Pt(5)) then
			Lvl=3'//二对//
                        if Pt(2)=Pt(3) AND Pt(4)=Pt(5) then
                        MaxPt=Pt(2)
                        Pair=Cr(2)
                        else
                        MaxPt=Pt(1)
                        Pair=Cr(1)
                        end if
                        else
			Lvl=2'//对子//
                        if Pt(1)=Pt(2) then
                        MaxPt=Pt(1)
                        Pair=Cr(1)
                        elseif Pt(2)=Pt(3) then 
                        MaxPt=Pt(2)
                        Pair=Cr(2)
                        elseif Pt(3)=Pt(4) then 
                        MaxPt=Pt(3)
                        Pair=Cr(3)
                        elseif Pt(4)=Pt(5) then 
                        MaxPt=Pt(4)
                        Pair=Cr(4)
                        end if
                        end if
		Else
			Lvl=1'//散牌一堆//
		End If 

		'FOR DEBUG
		'Response.Write "擂主:" & T_Pt(1) & "," & T_Pt(2) & "," & T_Pt(3) & "," & T_Lvl & "<br />"
		'Response.Write "攻擂:" & Pt(1) & "," & Pt(2) & "," & Pt(3) & "," & Lvl & "<br />"

		'//计算胜负//
		If T_Lvl>Lvl Then'//主级别大获胜//
			Ret=1
		ElseIf T_Lvl<Lvl Then'//攻级别大获胜//
			Ret=2
		Else'//同级牌//
			If T_Lvl=9 Then'//同花顺//
				If Pt(1)>T_Pt(1) Then
					Ret=2
				Elseif Pt(1)=T_Pt(1) Then
                                        if Cr(1)>T_Cr(1) then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			ElseIf T_Lvl=8 Then'//比铁支//
				If Pt(2)>T_Pt(2) Then
					Ret=2
				Else
					Ret=1
				End If
			ElseIf T_Lvl=7 Then'//比葫芦//
				If Pt(3)>T_Pt(3) Then
					Ret=2
				Else
					Ret=1
				End If
			ElseIf T_Lvl=6 Then'//比同花//
				If Pt(1)>T_Pt(1) Then
					Ret=2
				Elseif Pt(1)=T_Pt(1) Then
                                        if Cr(1)>T_Cr(1) then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			ElseIf T_Lvl=5 Then'//比顺子//
				If Pt(1)>T_Pt(1) Then
					Ret=2
				Elseif Pt(1)=T_Pt(1) Then
                                        if Cr(1)>T_Cr(1) then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			Elseif T_Lvl=4 Then'//比三条//
				If Pt(3)>T_Pt(3) Then
					Ret=2
				Else
					Ret=1
				End If
			ElseIf T_Lvl=3 Then'//比二对//
				If MaxPt>T_MaxPt Then
					Ret=2
				Elseif MaxPt=T_MaxPt Then
                                        if Pair>T_Pair then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			ElseIf T_Lvl=2 Then'//比对子//
				If MaxPt>T_MaxPt Then
					Ret=2
				Elseif MaxPt=T_MaxPt Then
                                        if Pair>T_Pair then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			Else'//比散牌//
				If Pt(1)>T_Pt(1) Then
					Ret=2
				Elseif Pt(1)=T_Pt(1) Then
                                        if Cr(1)>T_Cr(1) then
                                        Ret=2
                                        else
					Ret=1
                                        end if
                                Else
                                        Ret=1
				End If
			End If
		End If
		End Function
    Public Function huase(str)
        dim a2
                a2=str mod 4
                if a2=0 then a2=4
        huase=a2
	End Function
   Public Function daxiao(str)
        dim a1,a2
                a2=str mod 4
                if a2<>0 then
                a1=int(str/4)+1
                else 
                a1=int(str/4)  
                end if
                a1=a1-1
                if a1=0 then a1=13
                daxiao=a1
	End Function
   Public Function daxiaoo(str)
        dim a1
        a1=str-4
        if a1<1 then 
        daxiaoo=a1+52
        else
        daxiaoo=a1
        end if
	End Function
   Public Function zajinn(str)
	Dim T_Pt(5)
	Dim T_Cr(5)
        For i=0 To UBound(str)
		T_Pt(i+1)=daxiao(str(i))
		T_Cr(i+1)=huase(str(i))
        Next

                Resort T_Pt
		If (T_Pt(1)=T_Pt(2) AND T_Pt(1)=T_Pt(3) AND T_Pt(1)=T_Pt(4)) OR (T_Pt(5)=T_Pt(2) AND T_Pt(5)=T_Pt(3) AND T_Pt(5)=T_Pt(4)) Then 
			zajinn="铁支"
		ElseIf  (T_Pt(1)-T_Pt(2)=1 AND T_Pt(2)-T_Pt(3)=1 AND T_Pt(3)-T_Pt(4)=1 AND T_Pt(4)-T_Pt(5)=1) Then
			If T_Cr(1)=T_Cr(2) AND T_Cr(1)=T_Cr(3) AND T_Cr(1)=T_Cr(4) AND T_Cr(1)=T_Cr(5) Then
				zajinn="同花顺"
			Else
				zajinn="顺子"
			End If
		ElseIf T_Cr(1)=T_Cr(2) AND T_Cr(1)=T_Cr(3) AND T_Cr(1)=T_Cr(4) AND T_Cr(1)=T_Cr(5) Then
			zajinn="同花"
		ElseIf (T_Pt(1)=T_Pt(3) AND T_Pt(2)=T_Pt(3)) OR (T_Pt(4)=T_Pt(3) AND T_Pt(5)=T_Pt(3)) OR (T_Pt(4)=T_Pt(3) AND T_Pt(2)=T_Pt(3)) Then
                        If (T_Pt(1)=T_Pt(2) AND T_Pt(4)=T_Pt(3) AND T_Pt(5)=T_Pt(3)) OR (T_Pt(4)=T_Pt(5) AND T_Pt(1)=T_Pt(3) AND T_Pt(2)=T_Pt(3)) then 
			zajinn="葫芦"
                        else
			zajinn="三条"
                        end if
		ElseIf T_Pt(1)=T_Pt(2) OR T_Pt(3)=T_Pt(4) OR T_Pt(2)=T_Pt(3) OR T_Pt(4)=T_Pt(5) Then 
                        if (T_Pt(1)=T_Pt(2) AND T_Pt(3)=T_Pt(4)) OR (T_Pt(1)=T_Pt(2) AND T_Pt(4)=T_Pt(5)) OR (T_Pt(2)=T_Pt(3) AND T_Pt(4)=T_Pt(5)) then
			zajinn="二对"
                        else
			zajinn="对子"
                        end if
		Else
			zajinn="散牌"
		End If
	End Function
end class
set sangong=new sangong_class
%>